test_runner: match dotfiles in default coverage exclude - #63401
Conversation
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #63401 +/- ##
==========================================
+ Coverage 90.23% 90.25% +0.02%
==========================================
Files 741 741
Lines 241194 241210 +16
Branches 45432 45430 -2
==========================================
+ Hits 217640 217704 +64
+ Misses 15129 15080 -49
- Partials 8425 8426 +1
🚀 New features to boost your workflow:
|
d807464 to
b0e1f2c
Compare
The default coverage exclude globs did not match dotfiles, so test files such as `test/.foo.test.js` were incorrectly included in coverage reports. Apply the `dot: true` minimatch option when matching the relative path so the default exclude patterns cover dotfiles, while keeping plain matching for the absolute path to avoid misinterpreting dot segments in the filesystem path (e.g. tmp dirs like `test/.tmp.0`). Fixes: nodejs#63397 Signed-off-by: semimikoh <ejffjeosms@gmail.com>
b0e1f2c to
8437db0
Compare
|
@avivkeller PTAL |
| function createCoverageMatcher(pattern) { | ||
| return { | ||
| __proto__: null, | ||
| relative: createMatcher(pattern, kMatchGlobPatternOptions), | ||
| absolute: createMatcher(pattern), | ||
| }; | ||
| } |
There was a problem hiding this comment.
Can't we pass the same options and thus and use the same matcher for both or no?
There was a problem hiding this comment.
Intentional — relative needs dot: true so the default exclude globs match project dotfiles like test/.foo.test.js (the point of this PR), but absolute deliberately leaves it off. Enabling dot: true there could make a glob unintentionally match a dot segment that shows up in the absolute path for unrelated reasons (e.g. an OS temp dir like test/.tmp.0), which isn't something the user's pattern was written to target.
There was a problem hiding this comment.
Shouldn't they be on par? As in, if we are changing this to include dots locally, wouldn't it make sense to also include them globally?
There was a problem hiding this comment.
Not quite symmetric on purpose — I actually tested this by flipping absolute to use dot: true too and running it against the exact test/**/* default pattern.
Node's own test runner puts NODE_TEST_TMPDIR under a dot-prefixed directory (test/.tmp.<n>/, see test/common/tmpdir.js). With dot: true on absolute, ** is allowed to traverse into .tmp.<n>, so the default test/**/* exclude pattern ends up matching the absolute path of any file running under that tmp dir — e.g. .../test/.tmp.0/logic-file.js matches test/**/*.js, even though logic-file.js is a normal source file that should stay covered.
absolute (dot:false, current) match: false // logic-file.js correctly stays covered
absolute (dot:true) match: true // logic-file.js gets wrongly excluded
Since basically every Node test that uses a tmpdir runs under test/.tmp.N/, making absolute symmetric with dot: true would cause widespread false-exclusions whenever coverage runs inside the Node source tree itself. relative only needs dot: true for * to match a leading dot in the basename (e.g. .foo.test.js); it doesn't need ** to traverse arbitrary dot directories the way absolute would.
The default coverage exclude patterns ... (본문)
Fixes: #63397
Problem
node --experimental-test-coverageincludes dotfile test files (e.g.test/.foo.cjs) in the coverage report even though the default exclude patterns are intended to drop everything undertest/. Non-dotfile siblings are correctly excluded.This is caused by
matchGlobPatterncalling minimatch withoutdot: true; minimatch's default behavior is to not match dot-prefixed entries unless the pattern itself starts with a dot.Reported in #63397.
Fix
lib/internal/fs/glob.js: extendmatchGlobPatternwith an optionaloptionsargument forwarded to minimatch. Fixed options (nocase,windowsPathsNoEscape, etc.) still take precedence so callers cannot accidentally override them.lib/internal/test_runner/coverage.js: route the four exclude/include match calls through a small helper that passes{ dot: true }. Applied to both exclude and include for consistency.Test
Added a new scenario to
test-runner-coverage-default-exclusion.mjsthat runstest/.dotfile.cjsexplicitly and asserts the dotfile does not appear in the coverage report under the default exclude patterns. The new fixturetest/.dotfile.cjsexercises the samelogic-file.jsas the existing fixtures.Fixes: #63397